<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>生命周期</title>
</head>
<script type="text/javascript" src="../js/vue.js"></script>
<body>
<div id="root">
  <h2 :style="{opacity}">欢迎学习vue</h2>
</div>
</body>
<script type="text/javascript">
  new Vue({
    el: "#root",
    data() {
      return {
        opacity: 1,
      }
    },
    //生命周期钩子
    //Vue完成模板解析并 初次 把真实dom元素放入页面后（挂载完毕）调用vue
    mounted() {
      setInterval(() => {
        this.opacity -= 0.01
        if (this.opacity <= 0) {
          this.opacity = 1
        }
      }, 16)
    },
  });
</script>
</html>
